package com.zhu.controller;


import com.zhu.pojo.entity.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Tag(name = "文件上传相关")
@RestController
public class FileUploadController {

    @Operation(summary = "上传文件")
    public Result<String> upload(MultipartFile file) throws IOException {
        // 把文件的内容存储到磁盘上
        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
        file.transferTo(new File(filename));
        return Result.success("url访问地址");
    }
}
